package org.example.sword2offer.primary;



/**
 * @author: lynn
 * @Descript: 统计一个数字在排序数组中出现的次数,重点是排序数组
 * @date: 2021/3/17 23:52
 * @version: 1.0
 */
public class Q37_GetNumberOfK_T {
    public static void main(String[] args) {
        //int[] array={6,5,4,3,3,3,3,2,1};
        int[] array={1,2,3,3,3,3,4,5,6};
        int k=3;
        System.out.println(getNumberk(array,k));
    }
    //统计k在array中出现的次数
    public static int getNumberk(int[] array,int k){
        if (array.length==0&&array==null){
            return 0;
        }
        if (array.length==1){
            return array[0]==k?1:0;
        }
        //二分法找k ，遍历两次，确定最左边和最右边的数
        int mid=0;
        int l=0;
        int r=array.length-1;
        int star=0; //最左边的k
        int end=0;  //最右边的k
        if (array[0]>=array.length-1){//递减
            for (int i=0;i<array.length-1;i++){
                mid=l+(r-l)>>2;
                //找左边界
                if (array[mid]>=k){
                    l=mid;
                }else {
                    r=mid;
                }
            }
            star=l;
            for (int i = 0; i < array.length-1; i++) {
                mid=l+(r-l)>>2;

            }

        }else {//递增

        }



        return 0;
    }
}
